package io.github.talelin.latticy.controller.v1;

import io.github.talelin.core.annotation.GroupRequired;
import io.github.talelin.core.annotation.PermissionMeta;
import io.github.talelin.core.annotation.PermissionModule;
import io.github.talelin.latticy.dto.product.ProductPage;
import io.github.talelin.latticy.service.ProductService;
import io.github.talelin.latticy.service.feign.ProductFeignService;
import io.github.talelin.latticy.vo.FindResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.Positive;

/**
 * @ClassName：ProductController
 * @Author: ljj
 * @Date: 2022/5/10 9:17
 */
@RestController
@RequestMapping("/v1/product")
@PermissionModule(value = "产品管理")
public class ProductController {

    @Autowired
    private ProductFeignService productFeignService;

    @PermissionMeta(value = "分页查询产品")
    @GroupRequired
    @PostMapping("/pageList")
    public FindResultVO pageList(@RequestBody ProductPage productPage) {
        return FindResultVO.success(productFeignService.pageList(productPage));
    }


    @PermissionMeta(value = "根据id查询")
    @GroupRequired
    @GetMapping("/findById/{id}")
    public FindResultVO findById(@PathVariable @Positive(message = "{id.positive}") Long id) {
        return FindResultVO.success(productFeignService.findById(id));
    }

    @PermissionMeta(value = "查看已审核的产品")
    @GroupRequired
    @GetMapping("/findAllByAudit")
    public FindResultVO findAllByAudit() {
        return FindResultVO.success(productFeignService.findAllByAudit());
    }


}
